﻿using System;
using FFIV.Lib.BusinessRules;
using FFIV.Lib.IView.Articles;
using FFIV.Lib.Utilities;

namespace FFIV.Lib.Controlers.Admin
{
	public class ManageArticleController
	{
		private readonly IArticlesManage m_View;

		public ManageArticleController(IArticlesManage view)
		{
			view.Controller = this;
			m_View = view;
		}
		public void LoadPage()
		{
			Permissions currentPermission = UsersUtility.GetCurrentUserRole();
			if (currentPermission == Permissions.Admin)
			{
				m_View.ArticleManageList = ArticlesRules.GetAllArticles();
			}
			else if (currentPermission == Permissions.Author)
			{
				Guid? userId = UsersUtility.GetCurrentUserId();
				if (userId.HasValue)
				{
					m_View.ArticleManageList = ArticlesRules.GetArticlesByUserId(userId.Value);
				}
			}
		}

		public void DeleteArticle(int id)
		{
			ArticlesRules.DeleteArticleById(id);
			LoadPage();
		}

		public void EditArticle(int ArticleId)
		{
			ArticlesRules.GetArticleById(ArticleId);
		}
	}
}
